<?
	include("../includes/main_inc.php");
	$r= new ReturnRecord();  // base object for returning data or raw queries
	
	if($_POST['Submit']){
		if($_POST['password']==$_POST['password2']){
			$m= new AddToDatabase();
			$m->AddPosts($_POST,$_FILES);
			$m->AddTable("affiliate");
			$m->AddNoDupe(array("email"));
			$m->DoStuff();
			//echo $m->SQL;
			if($m->Errors==""){
				
				$Message="Affiliate Added";
			}else{
				$Message=$m->Errors;
			}
		}else{
			$Message="Passwords Don't Match";
		}
	};
?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Affiliate Bubble Administration</title>

<link href="<?=$rootdir?>css/admin.css" rel="stylesheet" type="text/css">
<script src="<?=$rootdir?>jscript/menuArray.js" language="javascript"></script>
<script src="<?=$rootdir?>jscript/clock.js" language="javascript"></script>
<script>
	function SetPaymentType(){
		var PType=document.getElementById("paymentMethod").value;
		if(PType=="Deposit"){
			var CBank="";
			var CCheque="none";
		}else{
			var CBank="none";
			var CCheque="";
		}
		for(x=1;x<5;x++){
			document.getElementById("bankRow"+x).style.display=CBank;
		}
		for(x=1;x<7;x++){
			document.getElementById("chqRow"+x).style.display=CCheque;
		}
	}
</script>
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
</head>

<body onLoad="funClock();">
<?php include("../includes/header.php"); ?>
<table width="100%" border="0" cellspacing="25" cellpadding="0">
<tr>
<td valign="top" width="240"><div id="menu"><?php include("../menu/affiliatesmenu.php"); ?></div></td>
<td align="center" valign="top">

<div id="titleCompact">Add An Affiliate </div>

<div id="descriptionCompact">Complete the form fields below to add a Affiliate into the system. Once a Affiliate has been added, an automated email will be sent to the Affiliate to inform them of their login details.</div>

<div id="contentCompact">
<table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#E9EEF5">
<tr id="formHeader">
<td><strong>Enter member details</strong><strong></strong></td>
</tr>
<tr>
  <td align="center" bgcolor="#FFFFFF"><form name="form1" method="post" action="add.php">
    <?=$Message;?>
    <table width="400" border="0" align="center" cellpadding="0" cellspacing="10">
      <tr>
        <td width="130" height="30">Company Name:</td>
        <td width="354"><input name="companyName" type="text" class="formTextFields" id="companyName" value="<?=$_POST['companyName'];?>" size="40">
          *</td>
      </tr>
      <tr>
        <td height="30">Contact Name:</td>
        <td><input name="contactName" type="text" class="formTextFields" id="contactName" value="<?=$_POST['contactName'];?>" size="40">
          *</td>
      </tr>
      <tr>
        <td height="30">Email Address: </td>
        <td><input name="email" type="text" class="formTextFields" id="email" value="<?=$_POST['email'];?>" size="40">
          *</td>
      </tr>
      <tr>
        <td height="30">Phone:</td>
        <td><input name="phone" type="text" class="formTextFields" id="phone" value="<?=$_POST['phone'];?>" size="40">
          *</td>
      </tr>
      <tr>
        <td height="30">Username:</td>
        <td><input name="username" type="text" class="formTextFields" id="username" value="<?=$_POST['username'];?>" size="40">
          *</td>
      </tr>
      <tr>
        <td>Password:</td>
        <td><input name="password" type="password" class="formTextFields" id="password4" size="40">
          *</td>
      </tr>
      <tr>
        <td height="36">Confirm Password:</td>
        <td><input name="password2" type="password" class="formTextFields" id="password5" size="40">
          *</td>
      </tr>
      <tr>
        <td height="36" colspan="2"><input type="checkbox" name="checkbox" value="checkbox">
          I agree to the Bubble Affiliate Program <a href="#">Terms and Conditions</a>.</td>
      </tr>
      <tr>
        <td height="36" colspan="2"><input name="emailSubscribe" type="checkbox" value="checkbox" checked>
          I would like to receive 'The Juice' email updates including the weekly accommodation specials.</td>
      </tr>
    </table>
    <p><strong>Payment Details</strong></p>
    <table width="400" border="0" align="center" cellpadding="0" cellspacing="10">
      <tr>
        <td width="130" height="30">Select Payment Method:</td>
        <td width="354"><select name="paymentMethod" class="formTextFields"  id="paymentMethod" onChange="SetPaymentType()">
            <option value="Deposit" <?=($_POST['paymentMethod']=="Deposit" ? "selected" :"");?>>Direct Deposit</option>
            <option value="Cheque" <?=($_POST['paymentMethod']=="Cheque" ? "selected" :"");?>>Pay By Cheque</option>
          </select>
        </td>
      </tr>
      <tr id="bankRow1">
        <td height="30">Bank Name: </td>
        <td><input name="bankName" type="text" class="formTextFields" id="bankName" value="<?=$_POST['bankName'];?>" size="40"></td>
      </tr>
      <tr id="bankRow2">
        <td height="30">Name On Account: </td>
        <td><input name="bankAccount" type="text" class="formTextFields" id="bankAccount" value="<?=$_POST['bankAccount'];?>" size="40"></td>
      </tr>
      <tr id="bankRow3">
        <td height="30">BSB:</td>
        <td><input name="bankBsb" type="text" class="formTextFields" id="bankBsb" value="<?=$_POST['bankBsb'];?>" size="40"></td>
      </tr>
      <tr id="bankRow4">
        <td height="30">Account Number: </td>
        <td><input name="bankNumber" type="text" class="formTextFields" id="bankNumber" value="<?=$_POST['bankNumber'];?>" size="40"></td>
      </tr>
      <tr id="chqRow1">
        <td height="30">Address</td>
        <td><input name="chqAddress" type="text" class="formTextFields" id="chqAddress" value="<?=$_POST['chqAddress'];?>" size="40"></td>
      </tr>
      <tr id="chqRow2">
        <td height="30">Suburb</td>
        <td><input name="chqSuburb" type="text" class="formTextFields" id="chqSuburb" value="<?=$_POST['chqSuburb'];?>" size="40"></td>
      </tr>
      <tr id="chqRow3">
        <td height="30">State</td>
        <td><input name="chqState" type="text" class="formTextFields" id="chqState" value="<?=$_POST['chqState'];?>" size="40"></td>
      </tr>
      <tr id="chqRow4">
        <td height="30">Country</td>
        <td><input name="chqCountry" type="text" class="formTextFields" id="chqCountry" value="<?=$_POST['chqCountry'];?>" size="40"></td>
      </tr>
      <tr id="chqRow5">
        <td height="30">PostCode</td>
        <td><input name="chqPostcode" type="text" class="formTextFields" id="chqPostcode" value="<?=$_POST['chqPostcode'];?>" size="40"></td>
      </tr>
      <tr id="chqRow6">
        <td height="30">Name On Cheque</td>
        <td><input name="chqName" type="text" class="formTextFields" id="chqName" value="<?=$_POST['chqName'];?>" size="40"></td>
      </tr>
      <tr>
        <td height="30">GST:</td>
        <td><input name="gst" type="checkbox" id="gst" value="1" <?=($_POST['gst']==1 ? "checked" :"");?>>
          I am eligible to collect GST </td>
      </tr>
      <tr>
        <td>ABN:</td>
        <td><input name="abn" type="text" class="formTextFields" id="abn" value="<?=$_POST['abn'];?>" size="40"></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><input name="Submit" type="submit" class="formButton" onClick="MM_validateForm('companyName','','R','contactName','','R','email','','RisEmail','phone','','RisNum','username','','R','password4','','R','password5','','R');return document.MM_returnValue"  value="Sign Up"></td>
      </tr>
    </table>
  </form>
  <a href="search.php"></a></td>
</tr>
</table>

</div>

</td>
</tr>
</table>
</body>
</html>
